var Modal = require('./index');

function _Alert(opts){
	var _alert=new Modal({
		type:opts.type,
		mask:true,
		delayAutoClose:opts.delayAutoClose,
		alwaysCenter:true,
		yes:opts.yes||true,
		no:opts.no,
		yesText:opts.yesText,
		noText:opts.noText,
		onOK:opts.onOK,
		onShow:function(){
			opts.onShow&&opts.onShow();
		},
		onClose:function(){
			opts.onClose&&opts.onClose();
			_alert.delete();
		},
		innerHTML:`
			<div class="yss-layer-alerts">
			<div class="yss-layer-alert-hd">
				<i class="iconfont icon-${opts.type}"></i>
				<b>${opts.title||'提示'}</b>
			</div>
			<div class="yss-layer-alert-bd">
				${opts.content}
			</div>
			</div>
		`
	});
	_alert.show();
}

var Alert = function(){
	var alerts={
		info:'info',
		error:'error',
		success:'success'
	}
	for(var _type in alerts){
		alerts[_type]=function(_type){
			return function(opts){
				_Alert({
					type:_type,
					title:opts.title,
					content:opts.content,
					yes:opts.yes||true,
					no:opts.no,
					yesText:opts.yesText,
					noText:opts.noText,
					delayAutoClose:opts.delayAutoClose,
					onOK:opts.onOK,
					onClose:opts.onClose
				});
			}
		}(_type);
	}
	return alerts;
}();
	
module.exports = Alert;